package com.web_bloks.widget.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;
import com.web_bloks.user.client.StatusMessageServer;
import com.web_bloks.types.client.StateType;

/**
 * 
 * @author Jean-Lou Dupont
 *
 */
public class StatusWidget extends FlexTable 
	implements StatusMessageServer {

	public enum Status {
		NA, OK, WARNING, PENDING, ERROR
	}

	Image na, ok, warning, pending, error;
	
	public StatusWidget() {
		super();
		setup();
	}
	
	private void setup() {

		WidgetImageBundle bundle = (WidgetImageBundle) GWT.create( WidgetImageBundle.class );

		na = bundle.blank().createImage();
		ok = bundle.ok().createImage();
		warning = bundle.warning().createImage();
		pending = bundle.pending().createImage();
		error   = bundle.error().createImage();

		final WidgetMessages MSG = (WidgetMessages) GWT.create(WidgetMessages.class);
		
		na.setTitle(MSG.na());
		ok.setTitle(MSG.ok());
		warning.setTitle(MSG.warning());
		pending.setTitle(MSG.pending());
		error.setTitle(MSG.error());
		
		setWidget(0,0,na);
		setWidget(0,1,ok);
		setWidget(0,2,warning);
		setWidget(0,3,pending);
		setWidget(0,4,error);
		
		setStatus(StateType.OK);
	}
	public void setStatus(StateType status) {

		setAllInvisible();
		
		switch(status) {
		case NA:
			na.setVisible(true);
			break;
		case OK:
			ok.setVisible(true);
			break;
		case WARNING:
			warning.setVisible(true);
			break;
		case PENDING:
			pending.setVisible(true);
			break;
		case ERROR:
			error.setVisible(true);
			break;
		}
	}
	
	protected void setAllInvisible() {
		na.setVisible(false);
		ok.setVisible(false);
		warning.setVisible(false);
		pending.setVisible(false);
		error.setVisible(false);
	}
	
}//END